package com.example.backend.repository;

import com.example.backend.entity.Announcement;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AnnouncementRepository extends JpaRepository<Announcement, Long> {

    Page<Announcement> findByStatus(Announcement.AnnouncementStatus status, Pageable pageable);

    @Query("SELECT a FROM Announcement a WHERE a.status = 'PUBLISHED' ORDER BY a.isPinned DESC, a.createdAt DESC")
    List<Announcement> findPublishedAnnouncementsOrderedByPinnedAndDate();

    Page<Announcement> findByAuthorId(Long authorId, Pageable pageable);

    List<Announcement> findByIsPinnedTrueAndStatus(Announcement.AnnouncementStatus status);
}
